package com.example.esp8266.Library.Chart;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class TemperatureHumidityView extends View {

    private Paint paint;
    private float temperature = 25.1f;
    private float humidity = 26.7f;

    public TemperatureHumidityView(Context context) {
        super(context);
        init();
    }

    public TemperatureHumidityView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TemperatureHumidityView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setTextSize(50);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        // Draw temperature
        paint.setColor(Color.RED);
        canvas.drawText(temperature + "°C", 50, 100, paint);

        // Draw humidity
        paint.setColor(Color.BLUE);
        canvas.drawText(humidity + "%", 50, 200, paint);

        // Draw temperature arc
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(20);
        paint.setColor(Color.RED);
        canvas.drawArc(100, 300, 400, 600, -90, (temperature / 50) * 360, false, paint);

        // Draw humidity arc
        paint.setColor(Color.BLUE);
        canvas.drawArc(100, 700, 400, 1000, -90, (humidity / 100) * 360, false, paint);
    }

    public void setTemperature(float temperature) {
        this.temperature = temperature;
        invalidate();
    }

    public void setHumidity(float humidity) {
        this.humidity = humidity;
        invalidate();
    }
}